/**
 * 
 */
package ar.com.contable.ganancias.modelVO;

import org.eclipse.ui.views.properties.IPropertyDescriptor;

import ar.com.contable.ganancias.model.ItemValueModel;
import ar.com.contable.ganancias.util.LabelsBag;
import ar.com.contable.ganancias.util.Utils;

/**
 * Defines Row.
 * 
 * @author E420611
 */
public class ItemVO implements RowVO {

	private CategoryVO parent;
	private ItemValueModel[] models;
    private IPropertyDescriptor[] propertyDescriptors;
    
	/**
	 * Constructor.
	 * 
	 * @param name
	 * @param string
	 */
	public ItemVO(CategoryVO parent, ItemValueModel[] itemValues) {
		this.setParent(parent);
		this.setModels(itemValues);
	}

	/**
	 * @return the parent
	 */
	public CategoryVO getParent() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public void setParent(CategoryVO parent) {
		this.parent = parent;
	}

	//
	// public Float getValue(String monthCode){
	// return this.getModel().getMonths()[Utils.getMonthPosition(monthCode) -
	// 1].getValue(this.getName());
	// }
	//
	// private String getName() {
	// return LabelsBag.getLabelText(this.getNameCode());
	// }
	//
	// public void setValue(String monthCode, Float value){
	// this.getModel().getMonths()[Utils.getMonthPosition(monthCode) -
	// 1].setValue(this.getName(), value);
	// }

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return LabelsBag.getLabelText(this.getModels()[0].getNameCode());
	}

	/**
	 * @return the models
	 */
	public ItemValueModel[] getModels() {
		return models;
	}

	/**
	 * @param models
	 *            the models to set
	 */
	public void setModels(ItemValueModel[] models) {
		this.models = models;
	}

	@Override
	public boolean canModify(String property) {		
		return true;
	}

	@Override
	public String getValue(String property) {
		if (property.equals("detalle")){
			return this.toString();
		} else{
			return this.getModels()[Utils.getMonthPosition(property) - 1].getValue().toString();
		}
		
		
	}

	@Override
	public void modify(String property, Object value) {
		if (!property.equals("detalle")){
			try {
				float valueTemp = Float.parseFloat(value.toString());
				this.getModels()[Utils.getMonthPosition(property) - 1].setValue(valueTemp);
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
	}

	@Override
	public boolean hasChildren(Object element) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Object getParent(Object element) {
		// TODO Auto-generated method stub
		return this.getParent();
	}

	@Override
	public Object[] getChildren(Object parentElement) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getColumnText(int columnIndex) {
		if (columnIndex==0){
			return this.toString();
		}else{
			return this.models[columnIndex - 1].getValue().toString();
		}
	}


}
